<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="学期" prop="semId">
         <el-select v-model="queryParams.semId" filterable clearable placeholder="请选择学期">
           <el-option
             v-for="item in semsterList"
             :key="item.id"
             :label="item.title"
             :value="item.id"
             size="small">
           </el-option>
         </el-select>
       </el-form-item>
        <el-form-item label="班级" prop="classId">
          <el-select v-model="queryParams.classId" filterable clearable placeholder="请选择班级">
            <el-option
              v-for="item in queryClazzList"
              :key="item.id"
              :label="item.title"
              :value="item.id"
              size="small">
            </el-option>
          </el-select>
        </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="studentList">
      <el-table-column label="年级" align="center" prop="year" />
      <el-table-column label="班级" align="center" prop="className" />
      <el-table-column label="学号" align="center" prop="code" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center" prop="sex" :formatter="sexFormat" />
      <el-table-column label="学生类别" align="center" prop="type" :formatter="typeFormat" />
      <el-table-column label="手机号" align="center" prop="mobile" />
      <el-table-column label="民族" align="center" prop="nation" />
      <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
   
  </div>
</template>

<script>
import { listProgress } from "@/api/evaluate/evalResults";
import { selectSemster} from "@/api/base/semster";
import { selectClazz } from "@/api/base/clazz";

export default {
  name: "EvalProgress",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学期数据
      semsterList: [],
      // 班级表格数据
      queryClazzList: [],
      // 房间数据
      roomList: [],
      // 学生表格数据
      studentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 性别字典
      sexOptions: [],
      // 是否字典
      yesnoOptions: [],
      // 类别字典
      typeOptions: [],
      // 状态字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        classId: null,
        semId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        classId: [
          { required: true, message: "班级不能为空", trigger: "blur" }
        ],
        year: [
          { required: true, message: "年级不能为空", trigger: "blur" }
        ],
        code: [
          { required: true, message: "学号不能为空", trigger: "blur" }
        ],
        name: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        specId: [
          { required: true, message: "专业不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_user_sex").then(response => {
      this.sexOptions = response.data;
    });
    this.getDicts("sys_yes_no").then(response => {
      this.yesnoOptions = response.data;
    });
    this.getDicts("student_type").then(response => {
      this.typeOptions = response.data;
    });
    this.getDicts("common_status").then(response => {
      this.statusOptions = response.data;
    });
    /*
    selectSpecialty({status:'1'}).then(response => {
      this.specialtyList = response.rows;
    });
    */
    selectSemster({'status':1}).then(response => {
      this.semsterList = response.rows;
    });
    this.getQueryClazzList();
  },
  methods: {
    /** 查询学生列表 */
    getList() {
      this.loading = true;
      listProgress(this.queryParams).then(response => {
        this.studentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
     /** 查询班级列表 */
    getQueryClazzList() {
      this.loading = true;
      var p = {status:'1'};
      selectClazz(p).then(response => {
        this.queryClazzList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 性别字典翻译
    sexFormat(row, column) {
      return this.selectDictLabel(this.sexOptions, row.sex);
    },
    // 是否住校字典翻译
    isLodgeFormat(row, column) {
      return this.selectDictLabel(this.yesnoOptions, row.isLodge);
    },
    // 类别字典翻译
    typeFormat(row, column) {
      return this.selectDictLabel(this.typeOptions, row.type);
    },
    // 状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 状态字典翻译
    sfdbFormat(row, column) {
      return this.selectDictLabel(this.yesnoOptions, row.sfdb);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        classId: null,
        specId: null,
        year: null,
        code: null,
        name: null,
        sex: null,
        birthday: null,
        idcard: null,
        mobile: null,
        email: null,
        nation: null,
        isLodge: "0",
        type: null,
        userId: null,
        roomId: null,
        status: "0"
      };
      this.getFormClazzList();
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    }
  }
};
</script>
